import { defHttp } from '@/utils/http/axios';
import {
  IPlaceholderDownListResult,
  IRouteDownListResult,
  ISmsAddData,
  ISmsDetailResult,
  ISmsListResult,
  ITypeByIdResult,
  IWechatTemplateListResult,
  IWechatTemplateModifyData,
} from './type';
enum Api {
  smsList = '/admin/org/sms-template/getPageList',
  typeDownList = '/admin/sms-template-type/getDownList',
  typeTreeDownList = '/admin/sms-template-type/getTreeDownList',
  placeholderDownList = '/admin/sms-placeholder/getDownList',
  routeDownList = '/admin/sms-route/getDownList?templateType=',
  smsAdd = '/admin/org/sms-template/add',
  smsEdit = '/admin/org/sms-template/edit',
  smsDetail = '/admin/org/sms-template/getById/',
  smsDel = '/admin/org/sms-template/del/',
  typeById = '/admin/sms-template-type/getById/',

  wechatTemplateList = '/admin/wechat-template/getPageList',
  wechatTemplateModify = '/admin/wechat-template/modify',
  wechatTemplateListByTypeId = '/admin//wechat-template/listByTypeId',
  smsTemplateTop = '/admin/org/sms-template/top',
  wechatTemplateTop = '/admin/wechat-template/top'
}

/**
 * 短信模板置顶
 * @param params 
 * @returns 
 */
export function smsTemplateTop(params: { id: number, topOp: boolean }) {
  return defHttp.post({
    url: Api.smsTemplateTop,
    params,
  });
}

/**
 * 公众号模板置顶
 * @param params 
 * @returns 
 */
export function wechatTemplateTop(params: { id: number, topOp: boolean }) {
  return defHttp.post({
    url: Api.wechatTemplateTop,
    params,
  });
}

/**
 * @description 短信模板列表
 * @date
 * @export
 * @param
 */
export function SmsList(params) {
  return defHttp.get<ISmsListResult>({
    url: Api.smsList,
    params,
  });
}

/**
 * @description 短信消息类型列表
 * @date
 * @export
 * @param
 */
export function TypeDownList() {
  return defHttp.get<ISmsListResult>({
    url: Api.typeDownList,
  });
}

/**
 * @description 树消息类型列表
 * @date
 * @export
 * @param
 */
export function TypeTreeDownList() {
  return defHttp.get({
    url: Api.typeTreeDownList,
  });
}

/**
 * @description 短信占位符列表
 * @date
 * @export
 * @param
 */
export function PlaceholderDownList(templateType: number) {
  return defHttp.get<IPlaceholderDownListResult[]>({
    url: Api.placeholderDownList + `?templateType=${templateType}`,
  });
}

/**
 * @description 短信占位符列表
 * @date
 * @export
 * @param
 */
export function RouteDownList(id: number) {
  return defHttp.get<IRouteDownListResult[]>({
    url: Api.routeDownList + id,
  });
}

/**
 * @description 短信模板新增
 * @date
 * @export
 * @param
 */
export function SmsAdd(data: ISmsAddData) {
  return defHttp.post({
    url: Api.smsAdd,
    data,
  });
}

/**
 * @description 短信模板编辑
 * @date
 * @export
 * @param
 */
export function SmsEdit(data: ISmsAddData) {
  return defHttp.post({
    url: Api.smsEdit,
    data,
  });
}

/**
 * @description 短信模板详情
 * @date
 * @export
 * @param
 */
export function SmsDetail(id: any) {
  return defHttp.get<ISmsDetailResult>({
    url: Api.smsDetail + id,
  });
}

/**
 * @description 短信模板删除
 * @date
 * @export
 * @param
 */
export function SmsDel(id: number) {
  return defHttp.post({
    url: Api.smsDel + id,
  });
}

/**
 * @description 根据类型id获取类型详情
 * @date
 * @export
 * @param
 */
export function TypeById(id: number) {
  return defHttp.get<ITypeByIdResult>({
    url: Api.typeById + id,
  });
}

/**
 * @description 微信模板列表
 * @date
 * @export
 * @param
 */
export function WechatTemplateList(params) {
  return defHttp.get<IWechatTemplateListResult[]>({
    url: Api.wechatTemplateList,
    params
  });
}

/**
 * @description 微信模板编辑
 * @date
 * @export
 * @param
 */
export function WechatTemplateModify(data: IWechatTemplateModifyData) {
  return defHttp.post({
    url: Api.wechatTemplateModify,
    data,
  });
}

/**
 * @description 根据类型查询微信模板列表
 * @date
 * @export
 * @param
 */
export function WechatTemplateListByTypeId(params) {
  return defHttp.get({
    url: Api.wechatTemplateListByTypeId,
    params,
  });
}
